<?php defined('IN_KG') or exit('Access Invalid!'); ?>

<style>
    .btn{
        font: normal 12px/20px "microsoft yahei", arial;
        color: #FFF;
        background-color: #CCD0D9;
        text-align: center;
        vertical-align: middle;
        display: inline-block;
        height: 18px;
        padding: 5px 10px;
        border-radius: 3px;
        cursor: pointer;
        margin-top: 10px;
        width: 50px;
    }
    .bc{
        background-color: #5D9CEC;
    }
    .pagination {
        text-align: center;
        display: block;
        margin: 0 auto;
        padding: 15px 0;
    }
</style>
<table class="ncsc-default-table" style="color: #000000">
    <thead>
    <tr nc_type="table_header">
        <th class="w30"></th>
        <th class="w120">产品名称</th>
        <th class="w50">货号</th>
        <th class="w100">规格</th>
        <th class="w30">库存</th>
        <th class="w80">报警日期</th>
        <th class="w30">货物状态</th>
        <th class="w30">停止报警</th>
        <th class="w30">操作</th>
    </tr>
    </thead>
    <tbody>
    <?php if (!empty($output['goods_list'])) { ?>
        <?php foreach ($output['goods_list'] as $val) { ?>
            <tr id="tr_<?php echo $val['goods_id'];?>">
                <td>
                    <img src="<?php echo thumb($val,60)?>" alt="">
                </td>
                <td>
                    <a href="/wap/goods_detail.html?goods_id=<?php echo $val['goods_id']?>" target="_blank">
                        <?php echo $val['goods_name']?>
                    </a>
                </td>
                <td>
                    <?php echo $val['goods_serial']?>
                </td>
                <td>
                    <?php echo $val['goods_spec']?>
                </td>
                <td>
                    <?php echo $val['goods_storage']?>
                </td>
                <td>
                    <?php echo date('Y-m-d H:i',$val['warning_time'])?>
                </td>
                <td>
                    <?php if( $val['storage_status'] == 1){?>
                        <a  id="<?php echo $val['goods_id']?>_1" class="btn bc" st_status="<?php echo $val['storage_status']?>"  onclick="alter_statu(<?php echo $val['goods_id']?>,1)">已订货</a>
                        <a  id="<?php echo $val['goods_id']?>_2" class="btn" st_status="<?php echo $val['storage_status']?>" onclick="alter_statu(<?php echo $val['goods_id']?>,2)">厂家缺货</a>
                    <?php }else if ($val['storage_status'] == 2){ ?>
                        <a  id="<?php echo $val['goods_id']?>_1" class="btn" st_status="<?php echo $val['storage_status']?>" onclick="alter_statu(<?php echo $val['goods_id']?>,1)">已订货</a>
                        <a  id="<?php echo $val['goods_id']?>_2" class="btn bc" st_status="<?php echo $val['storage_status']?>" onclick="alter_statu(<?php echo $val['goods_id']?>,2)">厂家缺货</a>
                    <?php }else{?>
                        <a  id="<?php echo $val['goods_id']?>_1" class="btn" st_status="<?php echo $val['storage_status']?>" onclick="alter_statu(<?php echo $val['goods_id']?>,1)">已订货</a>
                        <a  id="<?php echo $val['goods_id']?>_2" class="btn" st_status="<?php echo $val['storage_status']?>" onclick="alter_statu(<?php echo $val['goods_id']?>,2)">厂家缺货</a>
                    <?php }?>
                </td>
                <td>
                    <a href="#" class="btn" onclick="stop_warning(<?php echo $val['goods_id']?>)">停止报警</a>
                </td>

                <td>
                    <span>
                        <a href="/index.php?control=store_goods_online&op=edit_goods&commonid=<?php echo $val['goods_commonid']; ?>" class="btn-bluejeans">
                            <i class="icon-edit"></i>编辑 <!--<p></p>-->
                        </a>
                    </span>
                </td>
            </tr>
        <?php } ?>
    <?php } else { ?>
        <tr>
            <td colspan="20" class="norecord">
                <div class="warning-option">
                    <i class="icon-warning-sign"></i>
                    <span><?php echo $lang['no_record']; ?></span>
                </div>
            </td>
        </tr>
    <?php } ?>
    </tbody>
    <tfoot>
    </tfoot>
</table>

<div class="pagination">
    <?php echo $output['nav_list']?>
</div>
<script src="<?php echo RESOURCE_SITE_URL; ?>/js/jquery.poshytip.min.js"></script>
<script src="<?php echo SHOP_RESOURCE_SITE_URL; ?>/js/store_goods_list.js"></script>
<script>
    $(function () {

    });
    function alter_statu(goods_id,status){
        if(status == 1){
            st_status = $("#"+goods_id+"_"+status).attr("st_status");
            if(st_status == 1){

            }

            $("#"+goods_id+"_"+status).addClass("bc");
            $("#"+goods_id+"_2").removeClass("bc");
        }else{
            $("#"+goods_id+"_"+status).addClass("bc");
            $("#"+goods_id+"_1").removeClass("bc");
        }
        $.post("index.php?control=storage_manager&op=change_status",{'goods_id':goods_id,'status':status},function(result){
            console.log(result);
        });
    }

    function stop_warning(goods_id){
        status = confirm('是否要停止该商品库存报警?');
        console.log(status);
        if(status == 'true'){
            $.post("index.php?control=storage_manager&op=stop_warning",{'goods_id':goods_id},function(result){
                console.log(result);
                $("#tr_"+goods_id).remove();
            });
        }

    }
</script>